import { useTableColumnProps } from '/@/hooks/table-column/props'
import { useFormatterNumberLocaleString } from '/@/hooks/formatter'

/**
 * 显示国际数字格式, 且默认4位小数
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @param maximumFractionDigits 保留小数的位数, 默认4
 * @returns tableColumn props
 */
export function useTableColumnNumberLocaleString<
  T extends Record<string, any>,
  P extends keyof T
>(
  prop: P,
  label: string,
  options: UseTableColumnProps<any, T, P> = {},
  maximumFractionDigits = 4
) {
  return useTableColumnProps(prop, label, {
    width: 180,
    align: 'right',
    formatter: (row: T) =>
      useFormatterNumberLocaleString(row[prop], maximumFractionDigits),
    ...options
  })
}
